﻿#include "CarVertify.h"
#include "ui_carvertify.h"

CarVertify::CarVertify(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::CarVertify)
{
    ui->setupUi(this);
    ui->labelCheckCardInfo->hide();
    time = new QLabel(ui->frameBottom);
    time->setGeometry(10, 10, 200, 40);
    time->setStyleSheet("QLabel{font: 20px; color: rgb(25, 25, 112);}");
    signal = new QLabel(ui->frameBottom);
    signal->setGeometry(700, 18, 41, 22);
    signal->setStyleSheet("QLabel{background-color:transparent;}");

    QDir dir(IMAGE_PATH);
    if(dir.exists())
    {
        ui->frameTop->setStyleSheet(LOGO_STY);
    }

    countdown = new CountDownTime(ui->frameMid);
    countdown->setGeometry(710, 10, 30, 40);
    countdown->mysetText("60");

    connect(countdown, SIGNAL(CoundDownTimeisOver()), this, SLOT(countdownOver()));
    keyBoardConnect();
}

CarVertify::~CarVertify()
{
    delete ui;
}

void CarVertify::on_buttonOk_clicked()
{
    /*待完成*/
    stackLayout->setCurrentIndex(chargeTypePage);
    ui->labelCheckCardInfo->show();
    QTimer::singleShot(3000,ui->labelCheckCardInfo,SLOT(hide()));//显示三秒后隐藏
}

void CarVertify::on_buttonBack_clicked()
{
    /*待完成*/
    stackLayout->setCurrentIndex(ChooseGunPage);
    countdown->CountDownStop();
}

void CarVertify::countdownOver()
{
    /*待完成*/
//    stackLayout->setCurrentIndex(ChooseGunPage);
    Init_Focus();
}

void CarVertify::on_Keyboard_clicked()
{
    QPushButton* btn =  static_cast<QPushButton*>(sender());

    QLineEdit* focus = (QLineEdit* )QApplication::focusWidget();

    keyHandle(btn, focus);

}

void CarVertify::keyHandle(QPushButton* btn, QLineEdit* lineEdit)
{
    if( btn->text() == tr("空格") )
    {
        lineEdit->insert(" ");
    }
    else if( btn->text() == tr("退格") )
    {
        lineEdit->backspace();
    }
    else if( btn->text() == tr("清除"))
    {
        lineEdit->clear();
    }
    else
    {
        lineEdit->insert(btn->text());
    }
}

void CarVertify::keyBoardConnect()
{
    connect(ui->One, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Tow, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Three, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Four, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Five, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Six, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Seven, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Eight, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Nine, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Zero, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->Remove, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
    connect(ui->RemoveAll, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
//    connect(ui->Char1, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
//    connect(ui->Char2, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
//    connect(ui->Space, SIGNAL(clicked()), this, SLOT(on_Keyboard_clicked()));
}
